home *** CD-ROM | disk | FTP | other *** search
- {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- (c) TechInsite Pty. Ltd.
- PO Box 429, Abbotsford, Melbourne. 3067 Australia
- Phone: +61 3 9419 6456
- Fax: +61 3 9419 1682
- Web: www.techinsite.com.au
- EMail: peter_hinrichsen@techinsite.com.au
-
- Created: October 1999
-
- Notes: Edit a row of data in the subject
-
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
- unit FObserver_Edit;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, Mask, ComCtrls, Spin,
- Subject_Portfolio, FObserver_Abstract ;
-
- type
-
- //--------------------------------------------------------
- TFormObserverEdit = class(TFormObserverAbstract)
- btnDone: TButton;
- Label4: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- eValue: TEdit;
- ePrice: TEdit;
- eQty: TEdit;
- sbPrice: TScrollBar;
- sbQty: TScrollBar;
- procedure btnDoneClick(Sender: TObject);
- procedure sbQtyChange(Sender: TObject);
- procedure sbPriceChange(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- // A pointer into the row of data to edit
- FData : TStockTrans ;
- procedure SetData(const Value: TStockTrans);
- public
- // A pointer into the row of data to edit
- property Data : TStockTrans read FData write SetData ;
- // Override the vitrual abstract DataToObserver method
- procedure DataToObserver ; override ;
- end;
-
- implementation
-
- {$R *.DFM}
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TFormPortfolioEdit
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- procedure TFormObserverEdit.DataToObserver ;
- begin
-
- if Data = nil then
- exit ; //==>
-
- // Set the position of the scrollBar(s)
- sbQty.Position := Data.Qty ;
- sbPrice.Position := trunc( Data.Price * 100 ) ;
-
- // Set the text to display
- eQty.Text := floatToStr( Data.Qty ) ;
- ePrice.Text := format( '%M', [ Data.Price ]) ;
- eValue.Text := format( '%M', [ Data.Value ]) ;
-
- end ;
-
- //----------------------------------------------------------
- procedure TFormObserverEdit.SetData(const Value: TStockTrans);
- begin
- // Save a pointer into the data we are interested in
- FData := Value;
- // Set the caption of the form so we know which row of
- // data we are editing
- Caption := ' Edit: ' + Data.StockName + ' (' + Data.StockCode + ')' ;
- // Read data from the subject into the form
- DataToObserver ;
- end;
-
- //----------------------------------------------------------
- procedure TFormObserverEdit.btnDoneClick(Sender: TObject);
- begin
- Subject.UpdateObservers ;
- Close ;
- end;
-
- // The Quantity scrollBar was changed
- //----------------------------------------------------------
- procedure TFormObserverEdit.sbQtyChange(Sender: TObject);
- begin
- // Set the new value in the subject
- Data.Qty := sbQty.Position ;
- // Update the observers, including this one
- Subject.UpdateObservers ;
- end;
-
- // The Price scrollBar was changed
- //----------------------------------------------------------
- procedure TFormObserverEdit.sbPriceChange(Sender: TObject);
- begin
- // Set teh new value in the subject
- Data.Price := sbPrice.Position / 100 ;
- // Update the observers, including this one
- Subject.UpdateObservers ;
- end;
-
- // Assing the subject when the observer is created
- //----------------------------------------------------------
- procedure TFormObserverEdit.FormCreate(Sender: TObject);
- begin
- inherited ;
- Subject := gPortfolio ;
- end;
-
- end.
-